<?php

namespace App\Http\Requests;

use App\Http\Requests\Traits\PostAttributes;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdatePostRequest extends FormRequest
{
    use PostAttributes;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title'        => ['required', 'between:2,255', Rule::unique('posts')->ignore($this->route('post'))],
            'slug'         => ['required', 'between:2,255', Rule::unique('posts')->ignore($this->route('post'))],
            'publish_date' => ['required', 'date_format:Y-m-d'],
            'body'         => ['required'],
        ];
    }
}
